﻿//using Microsoft.VisualBasic;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;


public class App_Functions_Info : Standard_Info
{
    public App_Functions_Info()
    {
        _Function_Type = "MENU";
    }

    private string _Function_Code;
    public string Function_Code
    {
        get { return _Function_Code; }
        set { _Function_Code = value; }
    }

    private string _Function_Name;
    public string Function_Name
    {
        get { return _Function_Name; }
        set { _Function_Name = value; }
    }

    private string _Function_Type;
    public string Function_Type
    {
        get { return _Function_Type; }
        set { _Function_Type = value; }
    }

    private string _Control_Name;
    public string Control_Name
    {
        get { return _Control_Name; }
        set { _Control_Name = value; }
    }

    private string _Function_Tree;
    public string Function_Tree
    {
        get { return _Function_Tree; }
        set { _Function_Tree = value; }
    }

    private bool _Has_Child;
    public bool Has_Child
    {
        get { return _Has_Child; }
        set { _Has_Child = value; }
    }

    private string _Roles_Allow;
    public string Roles_Allow
    {
        get { return _Roles_Allow; }
        set { _Roles_Allow = value; }
    }

    private string _Roles_Denied;
    public string Roles_Denied
    {
        get { return _Roles_Denied; }
        set { _Roles_Denied = value; }
    }

    private string _Users_Allow;
    public string Users_Allow
    {
        get { return _Users_Allow; }
        set { _Users_Allow = value; }
    }

    private string _Users_Denied;
    public string Users_Denied
    {
        get { return _Users_Denied; }
        set { _Users_Denied = value; }
    }

    private string _Units_Allow;
    public string Units_Allow
    {
        get { return _Units_Allow; }
        set { _Units_Allow = value; }
    }

    private string _Units_Denied;
    public string Units_Denied
    {
        get { return _Units_Denied; }
        set { _Units_Denied = value; }
    }

}

public class App_Functions_Controller : Standard_Controller
{
    #region "Contructor"
    private static App_Functions_Controller _instance;
    protected App_Functions_Controller()
    {
    }
    protected new void Dispose()
    {
        _instance = null;
    }
    private static object _syncLock = new object();
    public static App_Functions_Controller Instance()
    {
        if (_instance == null)
        {
            lock (_syncLock)
            {
                if (_instance == null)
                {
                    _instance = new App_Functions_Controller();
                }
            }
        }
        return _instance;
    }
    #endregion

    public DataTable List()
    {
        DataTable m_dtFunction = DataConnect.ExecuteTable(DataConnect.WorkingConnect, "PCK_FUNCTIONS.Functions_List");
        Globals.DataTable_SetKey(m_dtFunction, "Control_Name");
        return m_dtFunction;
    }

    public DataTable ListButton(string menuName)
    {
        DataTable m_dtButton = DataConnect.ExecuteTable(DataConnect.WorkingConnect, "PCK_FUNCTIONS.Functions_ListButton", menuName);
        Globals.DataTable_SetKey(m_dtButton, "Control_Name");
        return m_dtButton;
    }

    public DataTable ListMenu()
    {
        DataTable m_dtMenu = DataConnect.ExecuteTable(DataConnect.WorkingConnect, "PCK_FUNCTIONS.Functions_ListMenu");
        Globals.DataTable_SetKey(m_dtMenu, "Control_Name");
        return m_dtMenu;
    }

    public void Insert(App_Functions_Info objInfo)
    {
        this.ExecuteNonQuery("PCK_FUNCTIONS.Functions_Insert", objInfo.Function_Code, Globals.DB_GetNull(objInfo.Function_Name), Globals.DB_GetNull(objInfo.Function_Type), Globals.DB_GetNull(objInfo.Control_Name), Globals.DB_GetNull(objInfo.Function_Tree), objInfo.Has_Child);
    }

    public void Update(App_Functions_Info objInfo)
    {
        this.ExecuteNonQuery("PCK_FUNCTIONS.Functions_Update", objInfo.Function_Code, Globals.DB_GetNull(objInfo.Function_Name), Globals.DB_GetNull(objInfo.Function_Type), Globals.DB_GetNull(objInfo.Control_Name), Globals.DB_GetNull(objInfo.Function_Tree), Globals.DB_GetNull(objInfo.Roles_Allow), Globals.DB_GetNull(objInfo.Roles_Denied), Globals.DB_GetNull(objInfo.Users_Allow), Globals.DB_GetNull(objInfo.Users_Denied));
    }

    public void UpdateByRole(string funcCode, Int64 roleId, bool isAllow, bool isDenied)
    {
        this.ExecuteNonQuery("PCK_FUNCTIONS.Functions_UpdateByRole", funcCode, roleId, isAllow, isDenied);
    }

    public void UpdateByUser(string funcCode, Int64 userId, bool isAllow, bool isDenied)
    {
        this.ExecuteNonQuery("PCK_FUNCTIONS.Functions_UpdateByUser", funcCode, userId, isAllow, isDenied);
    }

    public void UpdateByUnit(string funcCode, Int64 unitId, bool isAllow, bool isDenied)
    {
        this.ExecuteNonQuery("PCK_FUNCTIONS.Functions_UpdateByUnit", funcCode, unitId, isAllow, isDenied);
    }

    public void Clear(System.DateTime lastUpdate, string funcCode)
    {
        this.ExecuteNonQuery("PCK_FUNCTIONS.Functions_Clear", lastUpdate, funcCode);
    }

    public App_Functions_Info SelectById(string sFunction_Code)
    {
        return CBO.FillObject<App_Functions_Info>(DataConnect.ExecuteRow(DataConnect.WorkingConnect, "PCK_FUNCTIONS.Functions_SelectById", sFunction_Code));
    }
}
